package com.wxg.domain.englishword;

import org.junit.BeforeClass;
import org.junit.Test;

import com.wxg.jfinal.util.JFinalUtils;

/**
 * 测试 sqlite + jfinal 对数据库的操作
 * 
 * @author pactera
 *
 */
public class EnglishWordDbClient {

	@BeforeClass
	public static void before() {
		JFinalUtils.startNonWeb();
	}

	/**
	 * 
	 * (1) Caused by: org.sqlite.SQLiteException: [SQLITE_CONSTRAINT_NOTNULL]  
	 * A NOT NULL constraint failed (NOT NULL constraint failed: t_englishword.creat_time)
	 * 
	 * (2) com.jfinal.plugin.activerecord.ActiveRecordException: 
	 * The attribute name does not exist: createTime
	 * 
	 * (3) com.jfinal.plugin.activerecord.ActiveRecordException: 
	 * The attribute name does not exist: creatTime
	 * 
	 * (4) java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
	 * 
	 */
	@Test
	public void testAdd() {
		Englishword word = new Englishword();
		//creat_time
		word.set("id", null).set("word", "book").set("createTime", "111").save();
//			.set("usaPath", "").set("britainPath", "")
//			.set("createTime", "")
//			.set("updateTime", "").save();
		Integer id = word.getId();
		Englishword result = Englishword.dao.findById(id);
		System.out.println( result.toJson() );
		
		Englishword word2 = new Englishword();
		word2.set("id", null).set("word", "book").set("createTime", "222").save();
		
		Integer id2 = word2.getId();
		Englishword result2 = Englishword.dao.findById(id2);
		System.out.println( result2.toJson() );
		
		boolean delFlag = Englishword.dao.deleteById(id);
		System.out.println(delFlag);
		System.out.println( Englishword.dao.deleteById(id2) );
	}
}
